package com.itheima.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAdvice {
    @Pointcut("execution(void com.itheima.dao.BookDao.update())")
    private void pt(){}
    @Pointcut("execution(int com.itheima.dao.BookDao.select())")
    private void ptx(){}
//    @Before("pt()")
    public void before(){
        System.out.println("before");
    }
//    @After("pt()")
    public void after(){
        System.out.println("after");
    }
//    @Around("pt()")
    public Object around( ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("around before advice");
        Object ret = pjp.proceed();
        System.out.println("around after advice");
        return ret;
    }
//    @Around("ptx()")
    public Object aroundSelect( ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("around before advice");
        Object ret = pjp.proceed();
        System.out.println("around after advice");
        return ret;

    }
    @AfterReturning("ptx()")
    public void afterReturning(){
        System.out.println("afterReturning advice");
    }
    @AfterThrowing("ptx()")
    public void afterThrowing(){
        System.out.println("afterThrowing advice");
    }


}
